package config

import (
	"fmt"
	"github.com/mitchellh/go-homedir"
	"os"
	"path"
)

// 判断文件夹是否存在
func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}

func UserHome() string {
		// Find home directory.
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		cfgDir := path.Join(home, ".sasuke")
		exist, err := PathExists(cfgDir)
		if err != nil {
			fmt.Printf("get dir error![%v]\n", err)
			return ""
		}
		if exist {

		} else {
			fmt.Printf("no dir![%v]\n", cfgDir)
			// 创建文件夹
			err := os.Mkdir(cfgDir, os.ModePerm)
			if err != nil {
				fmt.Printf("mkdir failed![%v]\n", err)
			} else {
				fmt.Printf("mkdir success!\n")
			}
		}
	return cfgDir
}



